package com.example.dairenkun.neufoodshop.activity;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

import com.example.dairenkun.neufoodshop.R;
import com.example.dairenkun.neufoodshop.adapter.CommentListAdapter;
import com.example.dairenkun.neufoodshop.bean.Order;
import com.example.dairenkun.neufoodshop.model.OrderModel;
import com.example.dairenkun.neufoodshop.service.CommentService;

import java.util.List;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

public class MyCommentActivity extends AppCompatActivity {
    private  RecyclerView recyclerView;
    int userid;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my_comment);
        recyclerView=(RecyclerView)findViewById(R.id.recycler_id_mycomment);
        recyclerView.setLayoutManager(new LinearLayoutManager(MyCommentActivity.this));
        getData();
    }
    private void getData() {
        Intent intent =getIntent();
        userid=Integer.valueOf(intent.getStringExtra("user_id"));
        //获取网上的数据/
       /* Retrofit retrofit=new Retrofit.Builder()
                .baseUrl("http://60.205.189.39/ ")
                .addConverterFactory(GsonConverterFactory.create())
                .build();
        CommentService Service=retrofit.create( CommentService.class);
        Call<List<Order>> call=Service.getCommentList(userid);*/
        OrderModel orderModel=new OrderModel();
        Call<List<Order>> call=orderModel.MyCommentList(userid);
        call.enqueue(new Callback<List<Order>>() {
            @Override
            public void onResponse(Call<List<Order>> call, retrofit2.Response<List<Order>> response)
            {
                List<Order> comments=response.body();
                recyclerView.setAdapter(new CommentListAdapter(MyCommentActivity.this,comments));
            }
            @Override
            public void onFailure(Call<List<Order>> call, Throwable t) {

            }
        });
    }
}
